// router/routes.js
import { getAsyncPage } from '@/utils/asyncComponentLoader'
import { processRoutePermissions } from '@/utils/routeUtils'
import water_data from './routes/water_data'
import electricty_data from './routes/electricty_data'
import gas_data from './routes/gas_data'
import systemManagement from './routes/system-management'
import device_center from './routes/device_center'
import warningCenter from './routes/warning-center'

const routes = [
    {
        path: '/',
        name: 'Home',
        component: getAsyncPage(() => import('@/views/Home/index.vue')),
        redirect: '/dashboard',
        children: [
            {
                path: 'dashboard',
                name: 'Dashboard',
                meta: {
                    title: '监控中心',
                    icon: 'home'
                },
                children: [
                    {
                        path: '',
                        name: 'SimpleDashboard',
                        component: getAsyncPage(() => import('@/views/Dashboard/SimpleDashboard/index.vue')),
                        meta: {
                            title: '主页',
                            permission: ['view_simple_dashboard'],
                            isHideOnMenu: true
                        }
                    },
                    {
                        path: 'big-screen',
                        name: 'BigScreenDashboard',
                        component: getAsyncPage(() => import('@/views/Dashboard/BigScreenDashboard/index.vue')),
                        meta: {
                            title: '大屏监控',
                            permission: ['view_big_screen'],
                            isHideOnMenu: true
                        }
                    }
                ]
            },
            {
                path: 'energy-data',
                name: 'EnergyData',
                meta: {
                    title: '能源数据',
                    icon: 'dataCenter'
                },
                children: [{
                    // 能碳监控
                    path: 'carbon',
                    name: 'Carbon',
                    component: getAsyncPage(() => import('@/views/EnergyData/GreenCarbon/index.vue')),
                    meta: {
                        title: '能碳监控',
                        permission: ['view_carbon_data']
                    }
                }, { ...water_data }, { ...electricty_data }, { ...gas_data },
                {
                    path: 'plan',
                    name: 'Plan',
                    component: getAsyncPage(() => import('@/views/EnergyData/EnergyPlan/index.vue')),
                    meta: {
                        title: '用能计划',
                        permission: ['view_plan', 'manage_plan'],
                    }
                }]
            },
            { ...device_center },
            { ...warningCenter },
            {
                path: 'user-info',
                name: 'UserInfo',
                component: getAsyncPage(() => import('@/views/UserInfo/index.vue')),
                meta: {
                    title: '个人中心',
                    permission: ['view_simple_dashboard'],
                    isHideOnMenu: true
                }
            },
            { ...systemManagement }
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: getAsyncPage(() => import('@/views/Login/index.vue')),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/test',
        name: 'Test',
        component: getAsyncPage(() => import('@/views/Test/index.vue')),
        meta: {
            title: '测试'
        }
    },
    {
        path: '/:pathMatch(.*)*',
        redirect: '/'
    }
]

export const baseRoutes = processRoutePermissions(routes)